Create a linked plotlyof the global data- and attribution- spaces. Typically consumed directly by shiny app.

radial_cheem_tour(
  cheem_ls,
  basis,
  manip_var,
  primary_obs = NULL,
  comparison_obs = NULL,
  do_add_pcp_segments = TRUE,
  pcp_shape = c(142, 124, 3),
  angle = 0.15,
  row_index = NULL,
  inc_var_nms = NULL,
  do_center_frame = TRUE,
  do_add_residual = FALSE
)

radial_cheem_tour_subplots(
  cheem_ls,
  basis,
  manip_var,
  primary_obs = NULL,
  comparison_obs = NULL,
  do_add_pcp_segments = TRUE,
  pcp_shape = c(142, 124, 3),
  angle = 0.15,
  row_index = NULL,
  inc_var_nms = NULL,
  do_center_frame = TRUE
)

Arguments

cheem_ls

A return from cheem_ls(), a list of data frames.

basis

A 1D projection basis, typically a return of basis_attr_df().

manip_var

The , number of the manipulation variable.

primary_obs

The rownumber of the primary observation. Its local attribution becomes the 1d projection basis, and the point it highlighted as a dashed line. Defaults to NULL, no primary observation highlighted.

comparison_obs

The rownumber of the comparison observation. Point is highlighted as a dotted line. Defaults to NULL, no comparison observation highlighted.

do_add_pcp_segments

Logical, whether or not to add parallel coordinate line segments to the basis display.

pcp_shape

The number of the shape character to add. Expects 142, 124, 3 '|' for plotly and gganimate or '+' in either respectively. Defaults to 142, '|' for plotly.

angle

The step size between interpolated frames, in radians. Defaults to .15.

row_index

Numeric index of selected observations. Defaults to TRUE; 1:n.

inc_var_nms

A vector of the names of the variables to include in the projection.

do_center_frame

Whether or not to scale by standard deviations away from the mean within each frame or not. Defaults to TRUE, helping to keep the animation centered.

do_add_residual

Whether of not to add a facet with a fixed y on residual. Doing so may cause issues with animation. Defaults to FALSE.

Value

ggtour (ggplot2 object with frame info) animation frames of a radial tour manipulating the contribution of a selected tour. Animated with spinifex::animate_* functions.

See also

Other cheem consumers: global_view(), run_app()

Examples

library(cheem)
library(spinifex)

## Classification:
X    <- penguins_na.rm[, 1:4]
clas <- penguins_na.rm$species
Y    <- as.integer(clas)

rf_fit  <- default_rf(X, Y)
## Long runtime for full datasets or complex models:
shap_df <- attr_df_treeshap(rf_fit, X, noisy = FALSE)
this_ls <- cheem_ls(X, Y, class = clas,
                     model = rf_fit,
                     attr_df = shap_df)

bas <- basis_attr_df(shap_df, rownum = 1)
ggt <- radial_cheem_tour(this_ls, basis = bas, manip_var = 1,
                          primary_obs = 1, comparison_obs = 2)
if (FALSE) {
animate_plotly(ggt)
if(FALSE) ## or animate with gganimate
  animate_gganimate(ggt) #, render = gganimate::av_renderer())

## Regression:
dat  <- amesHousing2018_NorthAmes
X    <- dat[, 1:9]
Y    <- log(dat$SalePrice)
clas <- dat$SubclassMS

rf_fit  <- default_rf(X, Y)
## Long runtime for full datasets or complex models:
shap_df <- attr_df_treeshap(rf_fit, X, noisy = FALSE)
this_ls <- cheem_ls(X, Y, class = clas,
                     model = rf_fit,
                     attr_df = shap_df)

bas <- basis_attr_df(shap_df, rownum = 1)
ggt <- radial_cheem_tour(this_ls, basis = bas, manip_var = 1)

animate_plotly(ggt)
if(FALSE) ## or animate with gganimate
  animate_gganimate(ggt, render = gganimate::av_renderer())
}


## Experimental radial tour made from plotly::subplots rather than facets
ggt <- radial_cheem_tour_subplots(this_ls, basis = bas, manip_var = 1)
animate_plotly(ggt)